/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package envioyreciboficheros;

import java.io.File;

/**
 *
 * @author oscarsoto
 */
public class prueba {

    public static void main(String[] args) {
        File nuevo = new File("/Users/oscarsoto/Documents/Scripts/prueba.jpg");

        double division = (double) nuevo.length();

        System.out.println(convertirTammano(division));


    }

    public static String convertirTammano(double division) {
        String tipo;

        if (division >= 1024) {
            division /= 1024;
            if (division >= 1024) {
                division /= 1024;
                if (division >= 1024) {
                    division /= 1024;
                    tipo = "Gb";
                } else {
                    tipo = "Mb";
                }
            } else {
                tipo = "Kb";
            }
        } else {
            tipo = "Bytes";
        }
        
        double redondeo = Math.round(division * 100.0) / 100.0;
        return Double.toString(redondeo) + " " + tipo;
    }
}
